/**
  ******************************************************************************
  * @file    FatFs/FatFs_USBDisk/Inc/main.h 
  * @author  MCD Application Team
  * @version V1.1.0
  * @date    13-March-2014 
  * @brief   Header for main.c module
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx_hal.h"

/* EVAL includes component */
///#include "stm322xg_eval.h"

/* FatFs includes component */
#include "ff_gen_drv.h"
#include "usbh_diskio.h"


#define MAIN_VER		0x10
#define SUB_VER_1		0x01
#define SUB_VER_2		0x00
#define SOFT_YEAR		0x15
#define SOFT_MONTH		0x08
#define SOFT_DATE		0x14


#define DRV_MMC			0
#define DRV_USB			1


#define OTG_HS_PRIO		0x05
#define SDIO_PRIO		0x02
#define SD_DMA_TX_PRIO	0x03
#define SD_DMA_RX_PRIO	0x03
#define TICK_PRIO		0x0f

///FEED DOG
#define DOG_PIN							GPIO_PIN_8
#define DOG_GPIO_PORT					GPIOB
#define __DOG_GPIO_CLK_ENABLE()			__GPIOB_CLK_ENABLE()

///ULPI Reset
#define ULPI_RESET_PIN					GPIO_PIN_14

///
///usb LED ctrl
#define USB_LED_PIN						GPIO_PIN_6
///Work LED
#define WORK_LED_PIN					GPIO_PIN_7
///Work LED
#define ERR_LED_PIN						GPIO_PIN_8
///Copy LED
#define COPY_LED_PIN					GPIO_PIN_9
///CFG LED
#define CFG_LED_PIN						GPIO_PIN_10
///UART TX LED
#define TX_LED_PIN						GPIO_PIN_11


///COPY LED Status
#define COPY_LED_STATUS_NORMAL			0
#define COPY_LED_STATUS_SIGNAL			1
#define COPY_LED_STATUS_USB				2
#define COPY_LED_STATUS_CF_ERROR		3
#define COPY_LED_STATUS_START_SIGNAL	4
#define COPY_LED_STATUS_FORMAT			5
#define COPY_LED_STATUS_USB_ERROR		6
#define COPY_LED_STATUS_USB_PROTECTED	7

typedef struct{
		
	uint8_t		CopyLedFlag;
	uint8_t		UsbCopyAll;
	uint16_t	WorkLedTm;
	uint16_t	CopyLedTm;
	uint16_t	TrNo;
	
	uint32_t	USB_SdStartSec;
	uint32_t	USB_SdTotSecCnt[2];
	uint16_t	USB_AnalogFileCnt[2];
	uint16_t	USB_AnalogFileRemain[2];
	
}APP_INFO, *pAPP_INFO;

typedef struct{
	
	uint32_t ID1;
	uint32_t ID2;
	
	uint16_t TrNo[2];
	uint32_t CopyTm;
	
	uint32_t JwSecStartNo;
	uint32_t JwSecCnt;
	
	uint32_t TestSecStartNo;
	uint32_t TestSecCnt;
	
	uint32_t StsSecStartNo;
	uint32_t StsSecCnt;
	
	uint32_t SigSecStartNo;
	uint32_t MaxSigFileCnt;
	
	uint32_t Jw_CopyStart;
	uint32_t Jw_CopyCnt;
	
	uint32_t Test_CopyStart;
	uint32_t Test_CopyCnt;
	
	uint32_t StsSec_CopyStart;
	uint32_t StsSec_CopyCnt;
	
	uint32_t AnaFile_CopyStart;
	uint32_t AnaFile_CopyCnt;
}SD_INFO, *pSD_INFO;

extern APP_INFO AppInfo;
extern SD_INFO SDInfo;

extern uint8_t RstF;
extern __IO uint32_t UsbTm;
extern __IO uint32_t UsbErrTm;
extern __IO uint32_t DlyTm;
extern uint16_t CopyLedTm;
extern uint16_t WorkLedTm;


void UsbMonitor(void);
void FeedDog(void);
void ResetULPI(void);
void DeResetULPI(void);
void EnableLED(uint16_t led, uint8_t enable);
void LedHandler(void);

void UpdateUsbCopyInfo(uint8_t err);

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
